//
//  MeLiveConstant.h
//  MeLive
//
//  Created by liulei on 2017/5/2.
//  Copyright © 2017年 liulei. All rights reserved.
//
#import "AppDelegate.h"

#ifndef K_MELIVE_CONSTANT
#define K_MELIVE_CONSTANT

// 屏幕宽/高
#define MeLiveScreenWidth  [UIScreen mainScreen].bounds.size.width
#define MeLiveScreenHeight [UIScreen mainScreen].bounds.size.height

// 首页的选择器的宽度
#define Home_Seleted_Item_W 60
#define DefaultMargin       10

#pragma mark - 颜色
// 颜色相关
#define Color(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define KeyColor Color(216, 41, 116)

#pragma mark - 通知
// 当前没有关注的主播, 去看热门主播
#define kNotifyToseeBigWorld @"kNotifyToseeBigWorld"
// 当前的直播控制器即将消失
#define kNotifyLiveWillDisappear @"kNotifyLiveWillDisappear"
// 点击了用户
#define kNotifyClickUser @"kNotifyClickUser"
// 自动刷新最新主播界面
#define kNotifyRefreshNew @"kNotifyRefreshNew"

#define kAlertTitle   @"温馨提示"

#pragma mark - 其他
// 上一次刷新的时间
#define kLastRefreshDate @"kLastRefreshDate"

#define WEAKSELF typeof(self) __weak weakSelf = self;

//color
#define UIColorFromRGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
#define UIColorFromRGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#define UIColorFrom16RGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue &0xFF0000) >>16))/255.0 green:((float)((rgbValue &0xFF00) >>8))/255.0 blue:((float)(rgbValue &0xFF))/255.0 alpha:1.0]

//version
#define CurrentSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]
#define NSVersionNumber_iOS_6_0 (CurrentSystemVersion >= 6.0)
#define NSVersionNumber_iOS_7_0 (CurrentSystemVersion >= 7.0)
#define NSVersionNumber_iOS_8_0 (CurrentSystemVersion >= 8.0)
#define NSVersionNumber_iOS_9_0 (CurrentSystemVersion >= 9.0)

// 防空判断
#define INT_TO_STRING(i)    [NSString stringWithFormat:@"%d", i]
#define Obj_TO_Sting(obj)   [NSString stringWithFormat:@"%@", obj]
#define ObjIsNotNull(a)                 (a != nil && a != [NSNull null])
#define NullObjToString(a)              (ObjIsNotNull(a) ? Obj_TO_Sting(a) : @"")

#define NullStringToString(a) (a?:@"")

#define kDataListKey         @"results"

//set btn image
#define SetBtnImages(btn,normalImage,highImage) { \
[btn setImage:[UIImage imageNamed:normalImage]  forState:UIControlStateNormal];\
[btn setBackgroundImage:highImage?[UIImage imageNamed:highImage]:nil  forState:UIControlStateHighlighted];}

//默认loading
#define AvatarLoadingDefaultImage    [UIImage imageNamed:@"me_loading_avatar_126.png"]

//hud提示相关
#define SetHUDFinishedText(TEXT) { \
[gApp.window bringSubviewToFront:gApp.appMBPHUB];\
[gApp.appMBPHUB setDelegate:(id<MBProgressHUDDelegate>)self];\
gApp.appMBPHUB.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];\
gApp.appMBPHUB.mode = MBProgressHUDModeCustomView; \
gApp.appMBPHUB.labelText = TEXT; \
[gApp.appMBPHUB hide:YES afterDelay:1.0];\
}

#define SetHUDStartText(TEXT) { \
[gApp.window bringSubviewToFront:gApp.appMBPHUB];\
gApp.appMBPHUB.labelText = TEXT;\
[gApp.appMBPHUB show:YES];\
}

#define SetHUDHidden  [gApp.appMBPHUB hide:YES]
#define SetHUDHiddenNoAnimate [gApp.appMBPHUB hide:NO]

#define SetHUDShowText(TEXT) {\
[gApp.window bringSubviewToFront:gApp.appMBPHUB];\
gApp.appMBPHUB.mode = MBProgressHUDModeText; \
gApp.appMBPHUB.labelText = TEXT;\
[gApp.appMBPHUB show:YES]; \
[gApp.appMBPHUB hide:YES afterDelay:1.5];\
}

#define SetHUDShowDetailText(TEXT) { \
[gApp.window bringSubviewToFront:gApp.appMBPHUB];\
gApp.appMBPHUB.mode = MBProgressHUDModeText;\
gApp.appMBPHUB.labelText = @"";\
gApp.appMBPHUB.detailsLabelText=TEXT;\
[gApp.appMBPHUB show:YES];\
[gApp.appMBPHUB hide:YES afterDelay:1.5];\
}

#define HUDShowRequestError(__TEXT__, __VIEW__)   {\
MBProgressHUD *failHud = [MBProgressHUD HUDForView:__VIEW__];\
if (!failHud) {\
failHud = [[MBProgressHUD alloc] initWithView:__VIEW__]; \
[__VIEW__ addSubview:failHud];\
}\
failHud.mode = MBProgressHUDModeText; \
failHud.labelText = __TEXT__; \
failHud.margin = 15.f;\
[failHud show:YES];\
[failHud hide:YES afterDelay:1.5];\
}

// log output
#ifdef DEBUG
#define LogToast(TEXT) SetHUDShowText(TEXT)
#define LogToast2(TEXT, VIEW) HUDShowRequestError(TEXT, VIEW)
#else
#define LogToast(__OBJ__) {}
#define LogToast2(__OBJ__) {}
#endif

#define gApp                            ((AppDelegate*)[[UIApplication sharedApplication] delegate])
#define gResMgr                         ((AppDelegate*)[[UIApplication sharedApplication] delegate]).resourceManager

#endif

